package com.ruoyi.project.system.files.controller;

import java.io.IOException;
import java.util.Date;
import java.util.List;

import com.masiyi.ffmpeg.template.FFmpegTemplate;
import com.ruoyi.project.system.user.domain.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.files.domain.VodFiles;
import com.ruoyi.project.system.files.service.IVodFilesService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 视频管理Controller
 * 
 * @author ruoyi
 * @date 2024-11-05
 */
@Controller
@RequestMapping("/system/files")
public class VodFilesController extends BaseController
{
    private String prefix = "system/files";

    @Autowired
    private IVodFilesService vodFilesService;

    @RequiresPermissions("system:files:view")
    @GetMapping()
    public String files()
    {
        return prefix + "/files";
    }

    @RequiresPermissions("system:files:detail")
    @GetMapping("/detail/{Id}")
    public String detail(@PathVariable("Id") Long Id, ModelMap mmap)
    {
        mmap.put("name", "video");
        mmap.put("video", vodFilesService.selectVodFilesById(Id));
        return prefix + "/detail";
    }
    /**
     * 查询视频管理列表
     */
    @RequiresPermissions("system:files:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VodFiles vodFiles)
    {
        startPage();
        List<VodFiles> list = vodFilesService.selectVodFilesList(vodFiles);
        return getDataTable(list);

    }

    /**
     * 导出视频管理列表
     */
    @RequiresPermissions("system:files:export")
    @Log(title = "视频管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VodFiles vodFiles)
    {
        List<VodFiles> list = vodFilesService.selectVodFilesList(vodFiles);
        ExcelUtil<VodFiles> util = new ExcelUtil<VodFiles>(VodFiles.class);
        return util.exportExcel(list, "视频管理数据");
    }

    /**
     * 新增视频管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存视频管理
     */
    @RequiresPermissions("system:files:add")
    @Log(title = "视频管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VodFiles vodFiles)
    {
        Subject subject = SecurityUtils.getSubject();
        User u= (User)subject.getPrincipal();
        vodFiles.setCreatedBy(u.getUserId());
        vodFiles.setUpdatedBy(u.getUserId());
        vodFiles.setCreatedAt(new Date());
        vodFiles.setUpdatedAt(new Date());

        return toAjax(vodFilesService.insertVodFiles(vodFiles));
    }

    /**
     * 修改视频管理
     */
    @RequiresPermissions("system:files:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        VodFiles vodFiles = vodFilesService.selectVodFilesById(id);
        mmap.put("vodFiles", vodFiles);
        return prefix + "/edit";
    }

    /**
     * 修改保存视频管理
     */
    @RequiresPermissions("system:files:edit")
    @Log(title = "视频管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VodFiles vodFiles)
    {
        Subject subject = SecurityUtils.getSubject();
        User u= (User)subject.getPrincipal();
        vodFiles.setUpdatedBy(u.getUserId());
        vodFiles.setUpdatedAt(new Date());

        return toAjax(vodFilesService.updateVodFiles(vodFiles));
    }



    /**
     * 删除视频管理
     */
    @RequiresPermissions("system:files:remove")
    @Log(title = "视频管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(vodFilesService.deleteVodFilesByIds(ids));
    }
}
